﻿using System;
using System.Web.UI;
using System.Web.UI.WebControls;

using Fuse8.ContentManagementFramework.Domain;

namespace Fuse8.ContentManagementFramework.Web.FormPowered
{
    public abstract class CmsBaseFormPageControlCreator : Control
    {
        #region Property

        public CmsPageControl PageControl { get; protected set; }

        #endregion

        #region Methods

        protected override void Render(HtmlTextWriter writer)
        {
            RenderPageControl(writer);

            base.Render(writer);
        }

        protected abstract void RenderPageControl(HtmlTextWriter writer);

        protected void RethrowModuleError(Exception ex)
        {
            Literal literal = new Literal();
            literal.Text = string.Format(@"<div class=""highlight-error""><p>Fuse8.ContentManagementFramework runtime error: <br/>Error loading control. PageControlID = {0}; <br/> Exception = {1}</p></div>",
                PageControl.Id,
                ex.InnerException != null ? string.Format("{0} : {1}", ex.Message, ex.InnerException) : ex.Message);

            this.Controls.Add(literal);
        }

        #endregion
    }
}
